package projeto1;

import java.util.Collection;

public class Validador {
	
	private String pattern = "~*([p-u]|true|false|)((->|v|<->|\\^)~*([p-u]|true|false|))*";
	
	public Validador(Collection<String> premissas)
	{
		init(premissas);
	}
	
	private void init(Collection<String> premissas)
	{		
		if(premissas != null && premissas.size() > 0){
			String s = "";
			
			for(String p : premissas)
			{
				s += p + "|";
			}
			
			pattern = pattern.replace("[p-u]|", s);
			System.out.println("------- "+s);
		}
		
	}
	
	public boolean analisar(String exp)
	{
		System.out.println(pattern);
		int count = 0;
		
		String t = "";
		for(char c: exp.toCharArray())
		{
			
			if(c == '(') count++;
			else if (c == ')') count--;
			else
			{
				t = t+c;
			}
			
			if(count < 0) return false;
		}
		
		boolean ret = (count != 0)? false: t.matches(pattern);; 

		return ret;
	}

}
